{extend name="base/base" /}
{block name="body"}

<div class="layui-row">
    <form id="main_form" class="layui-form layui-form-pane" action="" method="post" lay-filter="main-form-group">
        <!-- ==================================  隐藏区  ================================== -->
        <!--隐藏域-->

        <div class="layui-card">
            <div class="layui-card-body">
                <div class="layui-tab-item layui-show">

                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">排序</label>
                            <div class="layui-input-inline">
                                <input type="text" name="sort" value="50"
                                       lay-verify="required|number" lay-verType="tips"
                                       autocomplete="off"
                                       class="layui-input">
                            </div>
                            <div class="layui-form-mid layui-word-aux">升序 数字越小越靠前</div>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">参数分类</label>
                        <div class="layui-input-inline">
                            <input type="text" name="type"
                                   lay-verify="required|number" lay-verType="tips"
                                   autocomplete="off"
                                   class="layui-input"
                                   value="{$menuid}">
                        </div>
                        <div class="layui-form-mid layui-word-aux">升序 数字越小越靠前</div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">参数名称</label>
                        <div class="layui-input-inline">
                            <input type="text" name="title" lay-verify="required" lay-verType="tips" autocomplete="off"
                                   placeholder="请输入参数名称"
                                   class="layui-input" value="">
                        </div>
                        <div class="layui-form-mid layui-word-aux">中文解释，用于开发时，识别参数的意义</div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">参数编码</label>
                        <div class="layui-input-inline">
                            <input type="text" name="name" lay-verify="required" lay-verType="tips" autocomplete="off"
                                   placeholder="请输入参数名称"
                                   class="layui-input" value="">
                        </div>
                        <div class="layui-form-mid layui-word-aux">相当于Key，只允许输入大写字母、下划线、数字</div>
                    </div>

                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">参数值</label>
                        <div class="layui-input-block">
                            <textarea name="value" lay-verify="required"  placeholder="请输入内容" class="layui-textarea"
                                      style="height: 100px;"></textarea>
                        </div>
                    </div>

                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">备注</label>
                        <div class="layui-input-block">
                            <textarea name="remark" placeholder="请输入内容" class="layui-textarea"
                                      style="height: 100px;"></textarea>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">临时图片</label>
                        <div class="layui-input-inline">
                            <input type="text" id="upload_img_url" name="upload_img_url" autocomplete="off"
                                   placeholder="请输入标题"
                                   class="layui-input" readonly value="">
                        </div>
                        <div class="layui-input-inline layui-btn-container" style="width: auto;">
                            &nbsp;<button type="button" class="layui-btn layui-btn-primary" id="upload_img_btn"><i
                                class="layui-icon">&#xe67c;</i>上传图片
                        </button>
                            <button type="button" class="layui-btn layui-btn-primary" id="upload_img_preview"  onclick="show_one_pic(document.getElementById('upload_img_url').value)">预览图片
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <input type="hidden" name="id" value=""/>
        <!-- 按钮区 -->
        <div class="layui-form-item layui-layout-admin" style="display: none">
            <div class="layui-input-block">

                <div class="layui-footer" style="left: 0;">
                    <button id="form_save" lay-filter="form_save" class="layui-btn"
                            lay-submit="">
                        保存
                    </button>
                    <button id="form_reset" type="button" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </div>
    </form>
</div>


<script src="/static/stv/admin/layuiadmin/layui/layui.js"></script>
<script src="/static/stv/admin/js/admin.common.js"></script>
<script>

    var save_url = '{:url('admin/config/add')}';
    layui.config({
        base: '/static/stv/admin/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'laydate'], function(){
        var $ = layui.$
            ,admin = layui.admin
            ,element = layui.element
            ,layer = layui.layer
            ,laydate = layui.laydate
            ,form = layui.form;

        form.render(null, 'component-form-group');

        laydate.render({
            elem: '#LAY-component-form-group-date'
        });

        /* 自定义验证规则 */
        form.verify({
            title: function(value){
                if(value.length < 5){
                    return '标题至少得5个字符啊';
                }
            }
            ,pass: [/(.+){6,12}$/, '密码必须6到12位']
            ,content: function(value){
                layedit.sync(editIndex);
            }
        });

        /* 监听指定开关 */
        form.on('switch(component-form-switchTest)', function(data){
            layer.msg('开关checked：'+ (this.checked ? 'true' : 'false'), {
                offset: '6px'
            });
            layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
        });

        /* 监听提交 */
        form.on('submit(form_save)', function(data){
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            $.post(save_url, data.field, function (res) {
                try {
                    if(res.status==200) {
                        //重新刷新父窗口的数据区
                        parent.layui.table.reload('main-table'); //重载表格
                        parent.layer.close(index); //再执行关闭
                    }else{
                        layer.msg(res.message);
                    }
                } catch (e) {
                    layer.msg("异常");
                }

            }, "json");

            return false;
        });
    });

    layui.use('upload', function(){
        var upload = layui.upload;
        upload.render({
            elem: '#upload_img_btn'
            ,url: '{:url('admin/common/uploadPic')}' //上传接口
            ,done: function(res, index, upload){
                //获取当前触发上传的元素，一般用于 elem 绑定 class 的情况，注意：此乃 layui 2.1.0 新增
                var item = this.item;
                if (res.code == 0) {
                    item.closest(".layui-form-item").find("#upload_img_url").val(res.data.src);
                } else {
                    layer.msg(res.message);
                }
            }
        });
    });
</script>
{/block}
